﻿using Repetition.Domain;
using NHibernate;

namespace Repetition.Persistence.NHibernate
{
    public class PersistentListFactory : IListFactory
    {
        private ISession session;

        public PersistentListFactory() { }

        public PersistentListFactory(ISession session)
        {
            this.session = session;
        }

        public IProblemList CreateProblemList()
        {
            return new PersistentProblemList(new ProblemRepository(Session));
        }

        public ISubjectList CreateSubjectList()
        {
            return new PersistentSubjectList(new SubjectRepository(Session));
        }

        private ISession Session
        {
            get
            {
                if (session == null)
                    session = SessionFactorySingleton.OpenSession();

                return session;
            }
        }
    }
}
